﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UserFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.UserFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System;
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.UserFilter"/> type.
    /// </summary>
    public static class UserFilter
    {
        /// <summary>
        /// Filters the specified User Users.
        /// </summary>
        /// <param name="collection">The User Users.</param>
        /// <param name="objectToMatch">The User to match.</param>
        /// <returns>List of filtered Users</returns>
        public static IQueryable<User> Filter(this IObjectSet<User> collection, User objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from user in collection
                where (objectToMatch.Id == 0 || user.Id == objectToMatch.Id) &&
                (objectToMatch.Name == null || user.Name.Equals(objectToMatch.Name, StringComparison.InvariantCultureIgnoreCase))
                select user;
        }
    }
}